< previous page page_256 next page >

Page 256
In the Form_Load event, the ListItem objects (baseball teams) for the ListView's ListItem collection are created and added. As each ListItem is added to the ListItems collection, values are assigned to SubItems(1), (the "Win" column) and SubItems(2) (the "Loss" column) of the ListItem, itmX.
The Click event procedures of the menu items set the View property of the ListView control. The views are lvwIcons, lvwSmallIcons, lvwList, and lvwReport, respectively.
You have just seen a sample project that demonstrates the ListView's capability to display items. Like the ListBox control, the ListView control has many events and properties, such as the ItemClick event, designed to select and manipulate items.
The ItemClick event passes an object to your program, so you can take appropriate action:
Private Sub ListView1_ItemClick(ByVal Item As ComctlLib.ListItem)
    If Item.Text = "Magic Item" Then MsgBox "You clicked the magic item!"
End Sub
The ListView control also has properties to sort the report view based on a column header. By using the ColumnClick event, you can easily change the sort order to the selected column, as shown here:
Private Sub lvMain_ColumnClick(ByVal ColumnHeader As ComctlLib.ColumnHeader)
       lvMain.SortKey = ColumnHeader.Index - 1
       lvMain.Sorted = True
End Sub
As you may have noticed, you can rename items in a ListView by single-clicking the text. Two events, BeforeLabelEdit and AfterLabelEdit, let your program know which item the users are changing.
As you can see, the ListView is a fairly complex control. To discover all the features, you might try creating several sample programs to test all the properties and methods.
New Features of the ListView Control
If you have used the ListView control in prior versions of Visual Basic, you will be happy to know that it has been greatly enhanced for version 6. You have already seen one improvementthe ColumnHeaderIcons collection, which allows pictures to be displayed in the report view headings. Several additional features, which allow you to further improve the appearance of the ListView control, are listed here:
AllowColumnReorderThis property allows users to rearrange the column order in a lvwReport view. For example, set it to True on the sample project, and you should be able to click and drag the "Wins" column to the leftmost position in the report.
FullRowSelectThis new property makes the ListView an excellent candidate to replace the standard list box. As you may have noticed, the default behavior of the ListView is to allow item selection only by clicking the leftmost column. Setting the FullRowSelect property to True not only allows users to select by clicking any column, but also provides a visual indicator by extending the highlight bar across all columns.
GridLinesThis property controls whether gridlines are drawn on the report, which makes it look similar to an Excel spreadsheet.

 
< previous page page_256 next page >